<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<form id="fwzImportForm">
	<table width="100%" border="0" id="MenDianTable" cellpadding="0" cellspacing="0" class='edit_table'>
		<tr>
			<th>
				导入Excel
			</th>
			<td>
				<input type="file" name="file"  id="fileId" onchange="checkXLSType(this);"> 
				<input type="hidden" name="t"  id="t" > 
			</td>
		</tr>
		<tr>
			<th>&nbsp;</th>
			<td>
				<a class="k-button"  onclick="doImportFwzExcel()">导入</a>
				<a class="k-button"  onclick="downloadFwzExcel()" target="downloadFileIframe" >下载模板</a>
			</td>
		</tr>
		<tr >
			<td colspan="2">
			<div id="resultTr1" class="resultTr1"  style="display: none;">
					<span id="resultSpan" class="resultSpan">【导入成功】请关闭，刷新列表查看。</span>
					<span id="resultErrorSpan" class="resultErrorSpan">【结果信息】存在数据导入失败，请<a style="color: #f00;cursor:pointer" target="downloadFileIframe2" onclick="downLoadMendError();">下载查看</a>整理后再导。</span><br/>
			</div>
			</td>
		</tr>
	</table>
</form>
<form id="templateExcelForm" style="display: none;" method="post">
</form>

<form id="errorFileForm" style="display: none;" method="get"> <input name="fileFileName" value="" id="errorFileName"></form>
<iframe name="downloadFileIframe2"  style="display:none" ></iframe>

<iframe name="downloadFileIframe"  style="display:none" ></iframe>
<script type="text/javascript">
//下载模板
function downloadFwzExcel() {
	$("#templateExcelForm").attr("action","fuwuZhan/exportTemplate.xls").submit();
}
//下载错误数据
function downLoadMendError(){
	$("#errorFileForm").attr("action","fuwuZhan/exportErrorFile.xls?fileFileName="+$("#errorFileName").val()).submit();
}

//开始执行导入操作
function doImportFwzExcel(){
	showLoading("正在执行...");
	$("#resultTr1").hide();
	
    var val=document.getElementById("fileId").value;
	if(!val){
		showDialog("请上传文件");
		hideLoading();
		return;
	}
	$("#t").val(new Date());
	$("#fwzImportForm").ajaxSubmit({
		url:"fuwuZhan/impFwzExcel.do",
		type:"post", 
		dataType:"json", 
		success:function (data) {
			if (data.success) {
				if(data.errorFile){
					$(".resultTr1").show();
					$(".resultErrorSpan").show();
					$("#errorFileName").val(data.errorFile);
					$(".resultSpan").hide();
				}else{
					$(".resultTr1").show();
					$(".resultSpan").show();
					$(".resultErrorSpan").hide();
				}
			} else {
				showDialog("保存失败,原因->"+data.message);
			}
			hideLoading();
		}
	});
}
</script>